package com.usaas.search.controller.app;

import com.usaas.common.core.domain.AjaxResult;
import com.usaas.search.dto.PlatUserCollectDto;
import com.usaas.search.dto.PlatUserDto;
import com.usaas.search.interceptor.realnameauth.RealNameAuth;
import com.usaas.search.service.IPlatUserCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户收藏Controller
 *
 * @author Helios
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/app/search/platUserCollect")
public class AppPlatUserCollectController extends AppBaseController {

    @Autowired
    private IPlatUserCollectService platUserCollectService;

    /**
     * 查询客户端用户基础信息分页列表
     */
    @PostMapping("/page")
    public AjaxResult page(@RequestBody PlatUserCollectDto platUserCollectDto) {
        PlatUserDto userInfo = getUserInfo();
        platUserCollectDto.setUserId(userInfo.getId());
        return platUserCollectService.queryPage(platUserCollectDto);
    }

    /**
     * 获取用户收藏详细信息
     */
    @PostMapping(value = "/getInfo")
    public AjaxResult getInfo(@RequestBody PlatUserCollectDto platUserCollectDto) {
        return AjaxResult.success(platUserCollectService.queryById(platUserCollectDto.getId()));
    }

    /**
     * 新增用户收藏
     */
    @RealNameAuth
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody PlatUserCollectDto platUserCollectDto) {
        PlatUserDto userInfo = getUserInfo();
        platUserCollectDto.setUserId(userInfo.getId());
        return toAjax(platUserCollectService.add(platUserCollectDto));
    }


    /**
     * 删除用户收藏
     */
    @RealNameAuth
    @PostMapping("/del")
    public AjaxResult del(@RequestBody PlatUserCollectDto platUserCollectDto) {
        return toAjax(platUserCollectService.removeBatch(platUserCollectDto.getIds()));
    }

}
